$(function () {

    var itemIndex = 0;

    var tabLoadEndArray = [false, false];
    var tabScroolTopArray = [0, 0];
    var page0 = 0;
    var page1 = 1;
    var type = 0;
    var dropload = $('.khfxWarp').dropload({
        scrollArea: window,
        domDown: {
            domClass: 'dropload-down',
            domRefresh: '<div class="dropload-refresh">上拉加载更多</div>',
            domLoad: '<div class="dropload-load"><span class="loading"></span>加载中...</div>',
            domNoData: '<div class="dropload-noData">没有更多数据了</div>'
        },
        loadDownFn: function (me) {
            setTimeout(function () {
                if (tabLoadEndArray[itemIndex]) {
                    me.resetload();
                    me.lock();
                    me.noData();
                    me.resetload();
                    return;
                }
                if (itemIndex == 0) {
                	$.get("/load/searchmore", {page: page0,q: $('#kerword').val(),type: $('#searchtype').val()},function(result){
                		if(result.code == 0){
                			page0 ++;
                			if(type == 0){
                				$('#listUl').append(result.data);
                			}else{
                				$('#listUl').html(result.data);
                			}
                			if(!result.hasnext){
                				tabLoadEndArray[itemIndex] = true;
                			}
                		}
                	});
                }else if (itemIndex == 1) {
                	$.get("/load/searchauthmore", {page: page1,name: $('#kerword').val()},function(result){
                		if(result.code == 0){
                			page1 ++;
                			if(type == 0){
                				$('#userlist').append(result.data);
                			}else{
                				$('#userlist').html(result.data);
                			}
                			if(!result.hasnext){
                				tabLoadEndArray[itemIndex] = true;
                			}
                		}
                	});
                }
                me.resetload();
            }, 500);
        }
    });


    $('.Relevant-nav-li span').on('click', function () {
        tabScroolTopArray[itemIndex] = $(window).scrollTop();
        var $this = $(this);
        itemIndex = $this.data('index');
        $(window).scrollTop(tabScroolTopArray[itemIndex]);
        $('.Relevant-nav-li span').removeClass('Relevant-nav-liActive');
        $(this).addClass('Relevant-nav-liActive');
        $('.uuuuu').eq(itemIndex).show().siblings('.uuuuu').hide();
        if(type == 1){
        	tabLoadEndArray[itemIndex] = false;
        	$('#listUl').html('');
        	$('#userlist').html('');
        }
        if (!tabLoadEndArray[itemIndex]) {
            dropload.unlock();
            dropload.noData(false);
        } else {
            dropload.lock('down');
            dropload.noData();
        }
        dropload.resetload();
    });
    
    
    $("#sch").on('click',function(){
    	tabLoadEndArray[itemIndex] = false;
		tabScroolTopArray[itemIndex] = $(window).scrollTop();
	    $(window).scrollTop(tabScroolTopArray[itemIndex]);
    	if($('#kerword').val() == ''){
        	sstb.dialog("请输入你想搜索的内容");
        	return false;
        }
    	page0 = 0;
        page1 = 1;
        type = 1;
        if(itemIndex == 0){
        	$('#listUl').html('');
        }else if(itemIndex == 1){
        	$('#userlist').html('');
        }
		dropload.unlock();
	    dropload.noData(false);
	    dropload.resetload();
    })
    
  //触发手机搜索键
    $(".Headline-header-input").on('keypress',function(e) {
        var keycode = e.keyCode;
        var searchName = $(this).val();
        if(keycode=='13') {
            e.preventDefault();
            if($('#kerword').val() == ''){
            	sstb.dialog("请输入你想搜索的内容");
            	return false;
            }
            //请求搜索接口
            page0 = 0;
            page1 = 1;
            type = 1;
            if(itemIndex == 0){
            	$('#listUl').html('');
            }else if(itemIndex == 1){
            	$('#userlist').html('');
            }
    		dropload.unlock();
    	    dropload.noData(false);
    	    dropload.resetload();
        }
    });
});